//
//  BaseNavigationController.m
//  Dinner
//
//  Created by Alimjan on 15/10/21.
//  Copyright © 2015年 Alimjan. All rights reserved.
//

#import "BaseNavigationController.h"
#import "CustomNavigationAnimationController.h"
#import "SwipeUpInteractiveTransition.h"
#import "NoteTools.h"

#define NAVIGATIONIMAGE [NoteTools createImageWithColor:[NoteTools colorWithHexString:@"D2CAE0"]]
@interface BaseNavigationController ()<UINavigationControllerDelegate,UIGestureRecognizerDelegate>
{
    CustomNavigationAnimationController *customNavigationAnimationController;
    SwipeUpInteractiveTransition *customInteractionController;
}
@end

@implementation BaseNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    customNavigationAnimationController = [CustomNavigationAnimationController new];
    customInteractionController = [SwipeUpInteractiveTransition new];
    [self.navigationBar setBackgroundImage:NAVIGATIONIMAGE forBarMetrics:UIBarMetricsDefault];
    
/** 将默认的返回按钮标题偏移 **/
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -100) forBarMetrics:UIBarMetricsDefault];
    
/** 将默认的返回按钮图片替换 **/
    UIImage *img = [[UIImage alloc]init];
    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:img forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

    

    
    

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (nullable id <UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController
                                   interactionControllerForAnimationController:(id <UIViewControllerAnimatedTransitioning>) animationController NS_AVAILABLE_IOS(7_0){
    
    return customInteractionController.interacting ? customInteractionController : nil;
}

- (nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
                                            animationControllerForOperation:(UINavigationControllerOperation)operation
                                                         fromViewController:(UIViewController *)fromVC
                                                           toViewController:(UIViewController *)toVC  NS_AVAILABLE_IOS(7_0){
    
//    if(operation==UINavigationControllerOperationPush ){
        [customInteractionController wireToViewController:toVC];
//    }
    customNavigationAnimationController.reverse = operation==UINavigationControllerOperationPop;
    return customNavigationAnimationController;
}

-(BOOL)shouldAutorotate
{
    
    return NO;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return NO;
    
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (void)navigationController:(UINavigationController *)navigationController
       didShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated
{
    if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
}

@end
